#ifndef FROMCHARTVIEW_H
#define FROMCHARTVIEW_H

#include <QWidget>

// #define QCHARTS

#ifdef QCHARTS
#include <QtCharts/QLineSeries>
#include <QValueAxis>
#else
#include "qcustomplot.h"
#endif

#include <QTimer>

namespace Ui {
class FromChartView;
}

class FromChartView : public QWidget {
    Q_OBJECT

  public:
    explicit FromChartView(QWidget *parent = nullptr);
    ~FromChartView();

    void setSayCount(int value);
    int  getSayCount();
    void addValue(double v);
    void setBrowname(QString value);
    void setAlarmFlag(bool value);
    void setLimit(double value);
    void setShowFlag(bool value);
    bool getShowFlag();
    void setTheme(int i);
    void setPointSizeX(int i);

  public slots:
    void doTimerout();

  protected:
    // void paintEvent(QPaintEvent *event);

  private:
    Ui::FromChartView *ui;

    double v_max = -999999.0, v_min = 999999.0, v_range = 0;
#ifdef QCHARTS
    QLineSeries *seriesValue,  *seriesAlarm;
    // QSplineSeries *seriesValue,  *seriesAlarm;
    QValueAxis  *axisx, *axisy;
    QChart *chart;
#endif
    QTimer *t;

    double last_limit = 0.0, last_value = 0.0;

    bool showFlag = false;
    QVector<double> values, limits, x;
    // X轴显示最大点数
    int pointSizeX = 120;
    // 调整皮肤顺序
    int index[8] = {0, 2, 4, 6, 1, 3, 7};
    // 语音播报计数
    int sayCount = 0;

#ifdef QCHARTS
    void createChartView();
#else
    void createQCustomPlot();
    QCustomPlot *mPlot;
    QCPTextElement *title;

    QColor PanelColor = QColor(0xea, 0xf7, 0xff);
    QColor TextColor = QColor(0x38, 0x64, 0x87);
    QColor BorderColor = QColor(0xc0, 0xdc, 0xf2);
    QColor NormalColorStart = QColor(0xde, 0xf0, 0xfe);
    QColor NormalColorEnd = QColor(0xc0, 0xde, 0xf6);
    QColor DarkColorStart = QColor(0xf2, 0xf9, 0xff);
    QColor DarkColorEnd = QColor(0xda, 0xef, 0xff);
    QColor HighColor = QColor(0x38, 0x64, 0x88);
    QColor TextHighColor = QColor(0x0, 0x0, 0x37);
#endif

};

#endif // FROMCHARTVIEW_H
